'use strict';

const Controller = require('egg').Controller;

class listController extends Controller {
  //获取列表接口
  async getlist() {
    const { ctx } = this;
    const list = await ctx.service.list.getlist()
    ctx.body = {
      code: 200,
      msg: "列表获取成功",
      list
    };
  }
  //评论接口
  async addcomment() {
    const { ctx } = this;
    const { comment, username } = ctx.request.body;
    if (comment && username) {
      await ctx.service.list.addcomment(comment, username)
      ctx.body = {
        code: 200,
        msg: "评论成功",
      };
    }else{
      ctx.body = {
        code: 401,
        msg: "评论失败",
      };
    }

  }
}

module.exports = listController;
